package com.mylogger;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.impl.StaticLoggerBinder;

public class MyLoggerApplication {
	
	private static Logger myLogger = LoggerFactory.getLogger(MyLoggerApplication.class);
	
	public static void main(String[] args) throws IOException {
		
		myLogger.info("Info message");
		myLogger.debug("Debug message");
		myLogger.error("Error message");
		
		myLogger.info("Info about {}","infoObject");
		myLogger.debug("{} in debug mode","debugObject");
		myLogger.error("Accidently {} crashed","errorObject");
		
		MyLoggerFactory factory = (MyLoggerFactory) StaticLoggerBinder.getSingleton().getLoggerFactory();
		factory.setLevel(myLogger.getName(), MyLogLevel.DEBUG);
		testSequence(MyLogLevel.DEBUG);
		factory.setLevel(myLogger.getName(), MyLogLevel.INFO);
		testSequence(MyLogLevel.INFO);
		factory.setLevel(myLogger.getName(), MyLogLevel.ERROR);
		testSequence(MyLogLevel.ERROR);
		factory.setLevel(myLogger.getName(), MyLogLevel.OFF);
		testSequence(MyLogLevel.OFF);
		factory.setLevel(myLogger.getName(), MyLogLevel.INFO);
		System.out.println(myLogger.isErrorEnabled());
		System.out.println("Done!");
		System.in.read();
		
	}
	
	private static void testSequence(MyLogLevel level){
		myLogger.debug("debug message shown with " + level +" level");
		myLogger.info("info message shown with " + level +" level");
		myLogger.error("error message shown with " + level +" level");
	}
}
